package erupt_simultaneously;

/**
 * @Auther Jun jie Yi
 * @Date 10:22 2021/7/25
 */
public class Demo implements Runnable {

    int count = 0;

    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        int count = demo.getCount(demo);
        System.out.println(count);
    }

    public int getCount(Demo demo) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            new Thread(demo).start();
        }
        while(Thread.activeCount() > 2) {
            Thread.currentThread().getThreadGroup().list();//打印出当前线程组线程
            Thread.yield();
        }
        return count;
    }

    @Override
    public void run() {
        count ++;
    }
}